import request from "@/utils/request";
import type {
  GetUserResponse,
  GetSaveUserParams,
  GetUserListResponse,
} from "./model/userModel";
enum Api {
  getUserUrl = "/admin/acl/user",
  getSaveUserUrl = "/admin/acl/user/save",
  getUserToAssignUrl = "/admin/acl/user/toAssign",
  getUserDoAssignUrl = "/admin/acl/user/doAssign",
}
export const getUserApi = (page: number, limit: number, username: string) => {
  return request.get<any, GetUserResponse>(
    Api.getUserUrl + `/${page}/${limit}`,
    {
      params: {
        username,
      },
    }
  );
};
// 新增
export const getSaveUserApi = (data: GetSaveUserParams) => {
  return request.post<any, null>(Api.getSaveUserUrl, data);
};
// 根据用户获取角色数据
export const getUserToAssignApi = (id: string) => {
  return request.get<any, GetUserListResponse>(
    Api.getUserToAssignUrl + `/${id}`
  );
};
// 根据用户分配角色
export const getUserDoAssignApi = (userId: string, roleId: string[]) => {
  return request.post<any, null>(
    Api.getUserDoAssignUrl,
    {},
    {
      params: {
        userId,
        roleId: roleId.join(","),
      },
    }
  );
};
